package com.it2297.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.it2297.main.App;

public class salePieChart {
	private String prodname, status;
	private int product_id, quantity, order_id;
	private double single_price, Total_price;
	
	public salePieChart(){
		
	}
	public salePieChart( String prodname, String status, int product_id, int quantity, int order_id, double single_price, double Total_price){
		this.prodname = prodname;
		this.status = status;
		this.product_id = product_id;
		this.quantity = quantity;
		this.order_id = order_id;
		this.single_price = single_price;
		this.Total_price = Total_price;
		
	}
	
	public ArrayList<salePieChart > getPieChart(int month){
		ArrayList<salePieChart> pie = new ArrayList<salePieChart>();
		try {
			App.mySqlConnection.open();
			String sql = "SELECT * FROM americano.pieChart_View WHERE status = 'paid' AND month(Date) = ?";
			PreparedStatement ps = App.mySqlConnection.getConnection().prepareStatement(sql);
			ps.setInt(1, month);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				salePieChart pieChart = new salePieChart();
				pieChart.setAttributes(rs);
				pie.add(pieChart);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			App.mySqlConnection.close();
		}
		return pie;
	}
	public String getProdname() {
		return prodname;
	}
	public void setProdname(String prodname) {
		this.prodname = prodname;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public int getProduct_id() {
		return product_id;
	}
	public void setProduct_id(int product_id) {
		this.product_id = product_id;
	}
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	public double getSingle_price() {
		return single_price;
	}
	public void setSingle_price(double single_price) {
		this.single_price = single_price;
	}
	public double getTotal_price() {
		return Total_price;
	}
	public void setTotal_price(double total_price) {
		Total_price = total_price;
	}
	
	public int getOrderId(){
		return order_id;
	}
	public void setOrderId(int id){
		this.order_id = id;
	}
	
	private void setAttributes(ResultSet rs) {
		try {
			this.setProdname(rs.getString("prodname"));
			this.setProduct_id(rs.getInt("product_id"));
			this.setQuantity(rs.getInt("quantity"));
			this.setSingle_price(rs.getDouble("single_price"));
			this.setOrderId(rs.getInt("order_id"));
			this.setTotal_price(rs.getDouble("Total_price"));
			this.setStatus(rs.getString("status"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
